fix: wrap table literals in parentheses before indexing#40
fix: wrap table literals in parentheses before indexing#40afcondon wants to merge 1 commit intoUnisay:mainfrom
Conversation
In Lua, table constructor literals cannot be directly indexed without
parentheses. The expression `{ ["key"] = val }["key"]` is a syntax error,
while `({ ["key"] = val })["key"]` is valid.
This fix adds the same `wrapPrec PrecAtom` wrapping to `VarIndex` that
was already applied to `VarField`, ensuring table literals are properly
parenthesized when used with bracket indexing.
Fixes pattern matching on ADT constructors that would generate invalid
Lua like:
if "Mod∷Type.Ctor" == { ["$ctor"] = "Mod∷Type.Ctor" }["$ctor"] then
Now correctly generates:
if "Mod∷Type.Ctor" == ({ ["$ctor"] = "Mod∷Type.Ctor" })["$ctor"] then
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
btw i have another larger PR that migrates pslua to the new spago, if you want it. Also LLM generated but working for me. |
|
I see this failed CI but it was not a test that failed, the build ran out of space "copyFile: resource exhausted (No space left on device)" |
|
Hi Andrew, I am glad you're interested in using and contributing to this project! I see this PR delivers a fix without unit-test coverage. Please add a unit test (golden test) to demonstrate the problem being fixed (the idea is that without this fix the test should fail and in a way that is understandable) |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Lua syntax error when table constructor literals are directly indexed with bracket notation. In Lua, expressions like {key = val}[key] are invalid syntax, requiring parentheses: ({key = val})[key].
Changes:
- Modified
printVarfunction in the Lua printer to wrap table constructors in parentheses before bracket indexing, makingVarIndexconsistent with the existingVarFieldbehavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Hi there, i (Andrew) am submitting this PR but, full disclosure, the bug diagnosis, change and PR text were all prepared by Claude, an LLM. I watched it run the test suite and the logic seems sound so i'm pushing it upstream for your consideration. I very much hope this is helpful and not a burden.
In Lua, table constructor literals cannot be directly indexed without parentheses. The expression
{ ["key"] = val }["key"]is a syntax error, while({ ["key"] = val })["key"]is valid.This fix adds the same
wrapPrec PrecAtomwrapping toVarIndexthat was already applied toVarField, ensuring table literals are properly parenthesized when used with bracket indexing.Fixes pattern matching on ADT constructors that would generate invalid Lua like:
if "Mod∷Type.Ctor" == { ["$ctor"] = "Mod∷Type.Ctor" }["$ctor"] then
Now correctly generates:
if "Mod∷Type.Ctor" == ({ ["$ctor"] = "Mod∷Type.Ctor" })["$ctor"] then